/**
 *  通用缓存 访问接口
 *  需要jquery 提供支持.
 */
var _CACHE = {
	
};

var CacheType = [ 'TypesCache' , 'FunAuthorityCache' ];

var Cache = {
	get: function ( key , type , callback , crefresh ){
		if ('TypesCache' == type ) {			// 类型缓存 ， 枚举， 数据字典表.. （数据字典表尚未添加.）
			return Cache._typesCache[key]; 
		}
		if ('FunAuthorityCache' == type ) {		// 功能缓存， 目前手动加入 ，详见  _funAuthorityCache
			//return Cache ._funAuthorityCache[key];
			return {
				add:true,
				del:true,
				update:true
			}
		}
		if ('ListCache' == type ) {  
			if ( key == 'UsersList'){  
				this.ajax( key , "account" , callback);
			} else { 
				this.ajax(key , 'name',  callback);
			}
			/*if (!Cache._listCache[key] || crefresh) {
			} else {
				callback&&callback(Cache._listCache[key]);
				return Cache._listCache[key];
			}*/
		}
	},
	ajax : function ( key,  labelColumn , callback ) {
		Ajax.list({
			url: basePath + '/admin/clist',
			data:{
				column :labelColumn,
				tname : key.replace('List' , '').firstUpperCase()
			},
			callback: function ( data ) {
				Cache._listCache[key] = data;
				callback&&callback(Cache._listCache[key]);
			}
		})
	},
	set : function ( key , value , type ){
		
	},
	_listCache : {},
	_typesCache : null,
	_typesCacheDefault:{
		
	},
	_funAuthorityCache : null
};
Cache = $.extend( {} , top.Cache||{} );

if (!top.vm) {
	setTimeout(function (){
		Cache.load();
	} , 500);
}

children = [];

Cache.load = function (){
	Ajax.get({
		url: basePath + '/admin/system/types',
		callback : function ( data ){
			for ( var i in data) {
				data[i] = eval(data[i]);
				var temp = new Array();
				for ( var j in data[i] ) {
					if (data[i][j].visible == 'false') {
						continue;
					}
					temp.push(data[i][j]);
				}
				data[i] = temp;
			}
			Cache._typesCache = $.extend({} , Cache._typesCacheDefault , data) ;
		}
	})
}

Cache.reload = function (){
	Cache.load();
}

function getDeepestNode(data){
	if(data["children"] && data["children"].length > 0){
		for(var i = 0 ; i < data["children"].length; i++){
			children.push(getDeepestNode(data["children"][i]));
		}
	}else{
		return data;
	}
}

